package view.customer;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.border.TitledBorder;

import lib.MyUtils;
import controller.customer.CustomerControl;

public class CustomerMainPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private JButton btnCusAdd;
	private JButton btnCusCancel;
	private JButton btnCusDelete;
	private JButton btnCusEdit;
	private JButton btnCusSearch;
	private JButton btnCusUpdate;
	private JComboBox<String> cbbCusSearchby;
	private JScrollPane jScrollPane1;
	private JScrollPane jScrollPane2;
	private JLabel lblCusAddress;
	private JLabel lblCusBy;
	private JLabel lblCusEmail;
	private JLabel lblCusName;
	private JLabel lblCusID;
	private JLabel lblCusPhone;
	private JPanel pnCusInformation;
	private JPanel pnCusListcustomer;
	private JTable tblCusListcustomer;
	private JTextField txtCusEmail;
	private JTextField txtCusName;
	private JTextField txtCusPersonalID;
	private JTextField txtCusPhone;
	private JTextField txtCusSearch;
	private JTextArea txtaCusAddress;

	private CustomerControl controller;

	public CustomerMainPanel() {
		initComponents();
		MyUtils.doLoadCustomer(this);
	}

	private void initComponents() {

		pnCusListcustomer = new JPanel();
		jScrollPane1 = new JScrollPane();
		tblCusListcustomer = new JTable();
		txtCusSearch = new JTextField();
		lblCusBy = new JLabel();
		cbbCusSearchby = new JComboBox<String>();
		btnCusSearch = new JButton();
		pnCusInformation = new JPanel();
		lblCusName = new JLabel();
		txtCusName = new JTextField();
		txtCusPersonalID = new JTextField();
		lblCusID = new JLabel();
		lblCusAddress = new JLabel();
		txtCusEmail = new JTextField();
		lblCusEmail = new JLabel();
		txtCusPhone = new JTextField();
		lblCusPhone = new JLabel();
		btnCusDelete = new JButton();
		btnCusUpdate = new JButton();
		btnCusEdit = new JButton();
		jScrollPane2 = new JScrollPane();
		txtaCusAddress = new JTextArea();
		btnCusAdd = new JButton();
		btnCusCancel = new JButton();

		controller = new CustomerControl(this);
		setPreferredSize(new java.awt.Dimension(906, 480));

		pnCusListcustomer.setBackground(new java.awt.Color(255, 255, 255));
		pnCusListcustomer.setBorder(BorderFactory.createTitledBorder(null,
				"List Customer", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1,
						12), java.awt.Color.blue));

		tblCusListcustomer.setFont(new java.awt.Font("Calibri", 1, 12));
		tblCusListcustomer.addMouseListener(new CustomerControl(this));

		jScrollPane1.setViewportView(tblCusListcustomer);

		lblCusBy.setText("by");

		cbbCusSearchby.setModel(new DefaultComboBoxModel<String>(new String[] {
				"All" }));

		btnCusSearch.setFont(new java.awt.Font("Calibri", 1, 12));
		btnCusSearch.setIcon(new ImageIcon("icon/search.png"));
		btnCusSearch.setText("Search");
		btnCusSearch.addActionListener(controller);

		GroupLayout pn_cus_listcustomerLayout = new GroupLayout(
				pnCusListcustomer);
		pnCusListcustomer.setLayout(pn_cus_listcustomerLayout);
		pn_cus_listcustomerLayout
				.setHorizontalGroup(pn_cus_listcustomerLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								GroupLayout.Alignment.TRAILING,
								pn_cus_listcustomerLayout
										.createSequentialGroup()
										.addContainerGap(
												GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addComponent(txtCusSearch,
												GroupLayout.PREFERRED_SIZE,
												151, GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(lblCusBy)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(cbbCusSearchby,
												GroupLayout.PREFERRED_SIZE, 79,
												GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(btnCusSearch,
												GroupLayout.PREFERRED_SIZE, 90,
												GroupLayout.PREFERRED_SIZE)
										.addContainerGap())
						.addComponent(jScrollPane1,
								GroupLayout.Alignment.TRAILING));
		pn_cus_listcustomerLayout
				.setVerticalGroup(pn_cus_listcustomerLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								GroupLayout.Alignment.TRAILING,
								pn_cus_listcustomerLayout
										.createSequentialGroup()
										.addGroup(
												pn_cus_listcustomerLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																txtCusSearch,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(lblCusBy)
														.addComponent(
																cbbCusSearchby,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnCusSearch))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(jScrollPane1,
												GroupLayout.DEFAULT_SIZE, 196,
												Short.MAX_VALUE)));

		pnCusInformation.setBackground(new java.awt.Color(255, 255, 255));
		pnCusInformation.setBorder(BorderFactory.createTitledBorder(null,
				"Information", TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1,
						12), java.awt.Color.blue));

		lblCusName.setFont(new java.awt.Font("Calibri", 0, 12));
		lblCusName.setText("ID:");

		lblCusID.setFont(new java.awt.Font("Calibri", 0, 12));
		lblCusID.setText("Name:");

		lblCusAddress.setFont(new java.awt.Font("Calibri", 0, 12));
		lblCusAddress.setText("Address:");

		lblCusEmail.setFont(new java.awt.Font("Calibri", 0, 12));
		lblCusEmail.setText("Email:");

		lblCusPhone.setFont(new java.awt.Font("Calibri", 0, 12));
		lblCusPhone.setText("Phone:");

		btnCusDelete.setFont(new java.awt.Font("Calibri", 1, 12));
		btnCusDelete.setIcon(new ImageIcon("icon/em_delete.png"));
		btnCusDelete.setText("Delete");
		btnCusDelete.addActionListener(controller);
		btnCusDelete.setEnabled(false);

		btnCusUpdate.setFont(new java.awt.Font("Calibri", 1, 12));
		btnCusUpdate.setIcon(new ImageIcon("icon/save.png"));
		btnCusUpdate.setText("Update");
		btnCusUpdate.addActionListener(controller);
		btnCusUpdate.setEnabled(false);

		btnCusEdit.setFont(new java.awt.Font("Calibri", 1, 12));
		btnCusEdit.setIcon(new ImageIcon("icon/em_edit.png"));
		btnCusEdit.setText("Edit");
		btnCusEdit.setEnabled(false);
		btnCusEdit.addActionListener(controller);

		txtaCusAddress.setColumns(20);
		txtaCusAddress.setRows(5);
		jScrollPane2.setViewportView(txtaCusAddress);

		GroupLayout pn_cus_informationLayout = new GroupLayout(pnCusInformation);
		pnCusInformation.setLayout(pn_cus_informationLayout);
		pn_cus_informationLayout
				.setHorizontalGroup(pn_cus_informationLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_cus_informationLayout
										.createSequentialGroup()
										.addGroup(
												pn_cus_informationLayout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING)
														.addGroup(
																pn_cus_informationLayout
																		.createSequentialGroup()
																		.addGap(55,
																				554,
																				Short.MAX_VALUE)
																		.addComponent(
																				btnCusEdit,
																				GroupLayout.PREFERRED_SIZE,
																				100,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																pn_cus_informationLayout
																		.createSequentialGroup()
																		.addGap(52,
																				52,
																				52)
																		.addGroup(
																				pn_cus_informationLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.LEADING,
																								false)
																						.addGroup(
																								pn_cus_informationLayout
																										.createSequentialGroup()
																										.addComponent(
																												lblCusName)
																										.addPreferredGap(
																												LayoutStyle.ComponentPlacement.RELATED,
																												GroupLayout.DEFAULT_SIZE,
																												Short.MAX_VALUE)
																										.addComponent(
																												txtCusName,
																												GroupLayout.PREFERRED_SIZE,
																												156,
																												GroupLayout.PREFERRED_SIZE))
																						.addGroup(
																								pn_cus_informationLayout
																										.createSequentialGroup()
																										.addComponent(
																												lblCusID)
																										.addGap(18,
																												18,
																												18)
																										.addComponent(
																												txtCusPersonalID,
																												GroupLayout.PREFERRED_SIZE,
																												156,
																												GroupLayout.PREFERRED_SIZE)))
																		.addGap(53,
																				53,
																				53)
																		.addGroup(
																				pn_cus_informationLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.LEADING)
																						.addComponent(
																								lblCusEmail)
																						.addComponent(
																								lblCusPhone))
																		.addPreferredGap(
																				LayoutStyle.ComponentPlacement.RELATED,
																				GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.addGroup(
																				pn_cus_informationLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.TRAILING,
																								false)
																						.addComponent(
																								txtCusPhone)
																						.addComponent(
																								txtCusEmail,
																								GroupLayout.DEFAULT_SIZE,
																								166,
																								Short.MAX_VALUE))
																		.addGap(31,
																				31,
																				31)
																		.addComponent(
																				lblCusAddress)))
										.addPreferredGap(
												LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												pn_cus_informationLayout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING)
														.addGroup(
																GroupLayout.Alignment.TRAILING,
																pn_cus_informationLayout
																		.createSequentialGroup()
																		.addComponent(
																				btnCusUpdate,
																				GroupLayout.PREFERRED_SIZE,
																				100,
																				GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				btnCusDelete,
																				GroupLayout.PREFERRED_SIZE,
																				100,
																				GroupLayout.PREFERRED_SIZE))
														.addGroup(
																GroupLayout.Alignment.TRAILING,
																pn_cus_informationLayout
																		.createSequentialGroup()
																		.addComponent(
																				jScrollPane2,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)
																		.addGap(14,
																				14,
																				14)))
										.addGap(13, 13, 13)));
		pn_cus_informationLayout
				.setVerticalGroup(pn_cus_informationLayout
						.createParallelGroup(GroupLayout.Alignment.LEADING)
						.addGroup(
								pn_cus_informationLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												pn_cus_informationLayout
														.createParallelGroup(
																GroupLayout.Alignment.LEADING)
														.addGroup(
																pn_cus_informationLayout
																		.createSequentialGroup()
																		.addGroup(
																				pn_cus_informationLayout
																						.createParallelGroup(
																								GroupLayout.Alignment.LEADING)
																						.addGroup(
																								pn_cus_informationLayout
																										.createSequentialGroup()
																										.addGroup(
																												pn_cus_informationLayout
																														.createParallelGroup(
																																GroupLayout.Alignment.BASELINE)
																														.addComponent(
																																lblCusEmail)
																														.addComponent(
																																txtCusEmail,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																lblCusAddress))
																										.addPreferredGap(
																												LayoutStyle.ComponentPlacement.RELATED)
																										.addGroup(
																												pn_cus_informationLayout
																														.createParallelGroup(
																																GroupLayout.Alignment.LEADING)
																														.addComponent(
																																txtCusPhone,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																lblCusPhone)))
																						.addGroup(
																								pn_cus_informationLayout
																										.createSequentialGroup()
																										.addGroup(
																												pn_cus_informationLayout
																														.createParallelGroup(
																																GroupLayout.Alignment.BASELINE)
																														.addComponent(
																																txtCusName,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE)
																														.addComponent(
																																lblCusName))
																										.addPreferredGap(
																												LayoutStyle.ComponentPlacement.RELATED)
																										.addGroup(
																												pn_cus_informationLayout
																														.createParallelGroup(
																																GroupLayout.Alignment.BASELINE)
																														.addComponent(
																																lblCusID)
																														.addComponent(
																																txtCusPersonalID,
																																GroupLayout.PREFERRED_SIZE,
																																GroupLayout.DEFAULT_SIZE,
																																GroupLayout.PREFERRED_SIZE))))
																		.addGap(0,
																				0,
																				Short.MAX_VALUE))
														.addComponent(
																jScrollPane2,
																GroupLayout.DEFAULT_SIZE,
																68,
																Short.MAX_VALUE))
										.addGap(18, 18, 18)
										.addGroup(
												pn_cus_informationLayout
														.createParallelGroup(
																GroupLayout.Alignment.BASELINE)
														.addComponent(
																btnCusEdit,
																GroupLayout.PREFERRED_SIZE,
																25,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnCusUpdate,
																GroupLayout.PREFERRED_SIZE,
																25,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																btnCusDelete,
																GroupLayout.PREFERRED_SIZE,
																25,
																GroupLayout.PREFERRED_SIZE))));

		btnCusAdd.setFont(new java.awt.Font("Calibri", 1, 15));
		btnCusAdd.setIcon(new ImageIcon("icon/add.png"));
		btnCusAdd.setText("Add");
		btnCusAdd.setToolTipText("");
		btnCusAdd.addActionListener(new CustomerControl(this));

		btnCusCancel.setFont(new java.awt.Font("Calibri", 1, 15));
		btnCusCancel.setIcon(new ImageIcon("icon/clear.png"));
		btnCusCancel.setText("Clear");
		btnCusCancel.addActionListener(new CustomerControl(this));

		GroupLayout layout = new GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(GroupLayout.Alignment.LEADING)
				.addGroup(
						GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addGap(0, 5, Short.MAX_VALUE)
								.addGroup(
										layout.createParallelGroup(
												GroupLayout.Alignment.LEADING,
												false)
												.addComponent(
														pnCusListcustomer,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														pnCusInformation,
														GroupLayout.DEFAULT_SIZE,
														GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))
								.addContainerGap())
				.addGroup(
						layout.createSequentialGroup()
								.addGap(357, 357, 357)
								.addComponent(btnCusAdd,
										GroupLayout.PREFERRED_SIZE, 90,
										GroupLayout.PREFERRED_SIZE)
								.addGap(18, 18, 18)
								.addComponent(btnCusCancel)
								.addContainerGap(GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(
				GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(pnCusInformation,
								GroupLayout.PREFERRED_SIZE,
								GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(
								LayoutStyle.ComponentPlacement.UNRELATED)
						.addComponent(pnCusListcustomer,
								GroupLayout.DEFAULT_SIZE,
								GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addGap(18, 18, 18)
						.addGroup(
								layout.createParallelGroup(
										GroupLayout.Alignment.BASELINE)
										.addComponent(btnCusAdd,
												GroupLayout.PREFERRED_SIZE, 30,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(btnCusCancel,
												GroupLayout.PREFERRED_SIZE, 30,
												GroupLayout.PREFERRED_SIZE))
						.addContainerGap()));
	}

	public JButton getBtnCusAdd() {
		return btnCusAdd;
	}

	public void setBtnCusAdd(JButton btnCusAdd) {
		this.btnCusAdd = btnCusAdd;
	}

	public JButton getBtnCusCancel() {
		return btnCusCancel;
	}

	public void setBtnCusCancel(JButton btnCusCancel) {
		this.btnCusCancel = btnCusCancel;
	}

	public JButton getBtnCusDelete() {
		return btnCusDelete;
	}

	public void setBtnCusDelete(JButton btnCusDelete) {
		this.btnCusDelete = btnCusDelete;
	}

	public JButton getBtnCusEdit() {
		return btnCusEdit;
	}

	public void setBtnCusEdit(JButton btnCusEdit) {
		this.btnCusEdit = btnCusEdit;
	}

	public JButton getBtnCusSearch() {
		return btnCusSearch;
	}

	public void setBtnCusSearch(JButton btnCusSearch) {
		this.btnCusSearch = btnCusSearch;
	}

	public JButton getBtnCusUpdate() {
		return btnCusUpdate;
	}

	public void setBtnCusUpdate(JButton btnCusUpdate) {
		this.btnCusUpdate = btnCusUpdate;
	}

	public JComboBox<String> getCbbCusSearchby() {
		return cbbCusSearchby;
	}

	public void setCbbCusSearchby(JComboBox<String> cbbCusSearchby) {
		this.cbbCusSearchby = cbbCusSearchby;
	}

	public JPanel getPnCusInformation() {
		return pnCusInformation;
	}

	public void setPnCusInformation(JPanel pnCusInformation) {
		this.pnCusInformation = pnCusInformation;
	}

	public JPanel getPnCusListcustomer() {
		return pnCusListcustomer;
	}

	public void setPnCusListcustomer(JPanel pnCusListcustomer) {
		this.pnCusListcustomer = pnCusListcustomer;
	}

	public JTable getTblCusListcustomer() {
		return tblCusListcustomer;
	}

	public void setTblCusListcustomer(JTable tblCusListcustomer) {
		this.tblCusListcustomer = tblCusListcustomer;
	}

	public JTextField getTxtCusEmail() {
		return txtCusEmail;
	}

	public void setTxtCusEmail(JTextField txtCusEmail) {
		this.txtCusEmail = txtCusEmail;
	}

	public JTextField getTxtCusName() {
		return txtCusName;
	}

	public void setTxtCusName(JTextField txtCusName) {
		this.txtCusName = txtCusName;
	}

	public JTextField getTxtCusPersonalID() {
		return txtCusPersonalID;
	}

	public void setTxtCusPersonalID(JTextField txtCusPersonalID) {
		this.txtCusPersonalID = txtCusPersonalID;
	}

	public JTextField getTxtCusPhone() {
		return txtCusPhone;
	}

	public void setTxtCusPhone(JTextField txtCusPhone) {
		this.txtCusPhone = txtCusPhone;
	}

	public JTextField getTxtCusSearch() {
		return txtCusSearch;
	}

	public void setTxtCusSearch(JTextField txtCusSearch) {
		this.txtCusSearch = txtCusSearch;
	}

	public JTextArea getTxtaCusAddress() {
		return txtaCusAddress;
	}

	public void setTxtaCusAddress(JTextArea txtaCusAddress) {
		this.txtaCusAddress = txtaCusAddress;
	}
}
